//页面rem
// (function (doc, win) {
//           var docEl = doc.documentElement,
//             resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
//             recalc = function () {
//               var clientWidth = docEl.clientWidth;
// 			    //  var clientWidth = $(".nwrapper").width();
//               /*if (!clientWidth) return;*/
//               docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
			  
//             };
//           if (!doc.addEventListener) return;
//           win.addEventListener(resizeEvt, recalc, false);
//           doc.addEventListener('DOMContentLoaded', recalc, false);
// })(document, window);



//图片预加载
function lazyload(){
	// $('.lazyload').picLazyLoad({
	// threshold: 400
	// });
}

var userId,appId,token,serviceToken;

if(GetQueryString("userId")!=null){
	userId = GetQueryString("userId");
	localStorage.setItem('userId', userId);
}else{
	userId = localStorage.userId;
}

if(GetQueryString("appId")!=null){
	appId = GetQueryString("appId");
	localStorage.setItem('appId', appId);
}else{
	appId = localStorage.appId;
}

if(GetQueryString("token")!=null){
	token = GetQueryString("token");
	localStorage.setItem('token', token);
}else{
	token = localStorage.token;
}

if(GetQueryString("serviceToken")!=null){
	serviceToken = GetQueryString("serviceToken");
	localStorage.setItem('serviceToken', serviceToken);
}else{
	serviceToken = localStorage.serviceToken;
}


if(GetQueryString("serviceRefreshToken")!=null){
	serviceRefreshToken = GetQueryString("serviceRefreshToken");
	localStorage.setItem('serviceRefreshToken', serviceRefreshToken);
}else{
	serviceRefreshToken = localStorage.serviceRefreshToken;
}





//页面淡入效果
$(document).ready(function(e) {
	//图片延时加载
	lazyload();
	
	//设置本地缓存处理返回上一页重新加载
	localStorage.setItem('refreshed', 'true');	
	
	//返回
	$('.back').on('click', function() {
		window.history.back();
		localStorage.setItem('refreshed', 'false');
	});
	

	

	
	});


//获取url
function GetQueryString(name) {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(decodeURIComponent(r[2]));
    }
    return null;
}







$(document).ready(function(e) {
	//判断是否app
	if (GetQueryString("iosnav") == "false" || GetQueryString("iosnav") == "flase" ) {
		

		let ua = navigator.userAgent.toLowerCase();
		if (/iphone|ipad|ipod/.test(ua)) {
			$(".top,.tophr").hide();
		}

	}
});

function back_fun() {
		var jsonParams = {
			'funName': 'back_fun',
			'params': {}
		};
		native.nativeFun(jsonParams);
};


// 计算结束日期减当前日期剩余的天数
function DateDiffer(Date_end){
	//date1结束时间
	let date1 = new Date(Date_end);
	//date2当前时间
	let date2 = new Date();
	date1 = new Date(date1.getFullYear(), date1.getMonth(), date1.getDate());
	date2 = new Date(date2.getFullYear(), date2.getMonth(), date2.getDate());
	const diff = date1.getTime() - date2.getTime(); //目标时间减去当前时间
	const diffDate = diff / (24 * 60 * 60 * 1000);  //计算当前时间与结束时间之间相差天数
	return diffDate
 }


 function getYearMonth(){
	// 获取当前日期
	var date = new Date();
	// 获取当前月份
	var nowMonth = date.getMonth() + 1;
	// 获取当前是几号
	var strDate = date.getDate();
	// 添加分隔符“-”
	var seperator = "-";
	// 对月份进行处理，1-9月在前面添加一个“0”
	if (nowMonth >= 1 && nowMonth <= 9) {
	   nowMonth = "0" + nowMonth;
	}
	// 对月份进行处理，1-9号在前面添加一个“0”
	if (strDate >= 0 && strDate <= 9) {
	   strDate = "0" + strDate;
	}
	// 最后拼接字符串，得到一个格式为(yyyy-MM-dd)的日期
	return date.getFullYear() + seperator + nowMonth + seperator + strDate;
}


//强制升级
function version(ios_v,Android_v){
let upurl=window.location.href;

let h5version_Android="";
let h5version_ios="";

if(ios_v){
	h5version_Android=Android_v;
	h5version_ios=ios_v;
}else{

	if (upurl.indexOf("test") > 0) {
		// 测试环境
		 h5version_Android="1000";
	}else if (upurl.indexOf("dev.bm-intelligent.com:8888") > 0) {
		// 开发环境
		 h5version_Android="1000";
	}else{
		// 正式环境 && 本地环境
		 h5version_Android="1000";
	}

	h5version_ios="3.1.0";

}





let version="";
let showv_tc=false;
if(localStorage.getItem('version')){
	version= localStorage.getItem('version');
	let upua = navigator.userAgent.toLowerCase();
	
	if (/iphone|ipad|ipod/.test(upua)) {
		if(h5version_ios<version){
			showv_tc=true
		}
	}else if(/android/.test(upua)) {
		if(h5version_Android<version){
			showv_tc=true
		}
	}

	if(showv_tc){
		$("body").append('<div data-sensors-click class="v_tc"><div data-sensors-click class="v_tcb"><p data-sensors-click >提示</p><span>发现需要升级的版本，现在去更新？</span><em id="upgrade">确定</em></div></div>')
	}

	console.log("show_version",showv_tc);

}

}






$(function(){

	$("body").on("click", "#upgrade", function () {

		var jsonParams = {
			'funName': 'upgrade',
			'params': {}
		};
		native.nativeFun(jsonParams);

	})
	
})

 